package com.wfl.sampling.service.impl;
import com.wfl.sampling.dao.WxchatOrderDao;
import com.wfl.sampling.dao.WxchatPreOrderDao;
import com.wfl.sampling.dao.WxchatRefundDao;
import com.wfl.sampling.entity.WxchatOrderInformation;
import com.wfl.sampling.entity.WxchatPreOrder;
import com.wfl.sampling.entity.WxchatRefundInformation;
import com.wfl.sampling.service.WxChatOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxChatOrderServiceImpl implements WxChatOrderService {
    @Autowired
    private WxchatOrderDao wxchatOrderDao;
    @Autowired
    private WxchatRefundDao wxchatRefundDao;
    @Autowired
    private WxchatPreOrderDao wxchatPreOrderDao;
    //预下单表
    @Override
    public void savePreOrderAll(WxchatPreOrder wxchatPreOrder){
        wxchatPreOrderDao.insertPreOrder(wxchatPreOrder);
    }
    @Override
    public void updatePreOrderState(String state, String out_trade_no){
        wxchatPreOrderDao.updatePreOrderState(state,out_trade_no);
    }
    @Override
    public void deleteByOut_trade_no(String out_trade_no){
        wxchatPreOrderDao.deleteByOut_trade_no(out_trade_no);
    }
    @Override
    public List<WxchatPreOrder> findPreOrdersByOpenid(String openid){
        return wxchatPreOrderDao.findPreOrdersByOpenid(openid);
    }




    //订单表
    @Override
    public void saveOrderAll(WxchatOrderInformation wxchatOrderInformation){
         wxchatOrderDao.insertOrder(wxchatOrderInformation);
    }
    @Override
    public void updateOrder(String out_trade_no, String state){
        wxchatOrderDao.updateOrder(state,out_trade_no);
    }

    @Override
    public void deleteOrder(String out_trade_no){
        wxchatOrderDao.deleteByOut_trade_no(out_trade_no);
    }

    @Override
    public List<WxchatOrderInformation> findOrdersByOpenid(String openid,String trade_state){
        return wxchatOrderDao.findOrdersByOpenid(openid,trade_state);
    }

    @Override
    public WxchatOrderInformation findOrderById(String id){
        return wxchatOrderDao.findOrderById(id);
    }





    //退款表
    @Override
    public void saveRefundAll(WxchatRefundInformation wxchatRefundInformation){wxchatRefundDao.insertRefundOrder(wxchatRefundInformation);}
    @Override
    public void updateRefund(String out_trade_no, String state, String pay_refund){
        wxchatRefundDao.updateRefund(out_trade_no,state,pay_refund);
    }
    @Override
    public void deleteRefund(String out_trade_no){
        wxchatRefundDao.deleteByOut_trade_no(out_trade_no);
    }
    @Override
    public List<WxchatRefundInformation> findRefundsByOpenid(String openid){
        return wxchatRefundDao.findRefundsByOpenid(openid);
    }
    @Override
    public WxchatRefundInformation findRefundById(String id){
        return wxchatRefundDao.findRefundById(id);
    }
}
